<?php

namespace App\Models\Shop;

use Illuminate\Database\Eloquent\Model;

class Address extends Model
{
    protected $guarded = [];

    public function orders()
    {
        return $this->hasMany('App\Models\Shop\Order');
    }

    static function all_addresses()
    {
        $customer_id = auth('api')->user()->id;
        $addresses = self::where('customer_id', $customer_id)->get();
        foreach ($addresses as $k => $v) {
            $xing = substr($v['tel'], 3, 4);  //获取手机号中间四位
            $addresses[$k]['tel'] = str_replace($xing, '****', $v['tel']);
        }

        return compact('addresses');
    }

}
